"""
URL configuration for TGDjango project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from api.views import TaskViewSet, TextEmbeddingView, QAView
from api.views import KnowledgeBaseViewSet
from api.views import ProcessingDataViewSet
from django.contrib import admin
from django.urls import path, include
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from django.urls import re_path

router = DefaultRouter()
router.register(r'tasks', TaskViewSet)
router.register(r'knowledge-bases', KnowledgeBaseViewSet)
router.register(r'processing-data', ProcessingDataViewSet)

# Swagger 配置
schema_view = get_schema_view(
    openapi.Info(
        title="Your API Title",  # API 的标题
        default_version='v1',  # API 的版本
        description="API documentation for your project",  # API 的描述
        terms_of_service="https://www.google.com/policies/terms/",  # 服务条款链接
        contact=openapi.Contact(email="contact@yourapi.local"),  # 联系信息
        license=openapi.License(name="BSD License"),  # 许可证信息
    ),
    public=True,
    permission_classes=(permissions.AllowAny,),  # 允许任何人访问
)


urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include(router.urls)),
    path('api/embed-text/', TextEmbeddingView.as_view(), name='embed-text'),
    path('api/qa/', QAView.as_view(), name='qa'),
    path('api/knowledge-bases/<int:pk>/upload-file/', KnowledgeBaseViewSet.as_view({'post': 'upload_file'}), name='upload-file'),
    path('api/knowledge-bases/<int:pk>/download-file/', KnowledgeBaseViewSet.as_view({'get': 'download_file'}), name='download-file'),
    path('api/knowledge-bases/<int:pk>/delete-file/', KnowledgeBaseViewSet.as_view({'delete': 'delete_file'}), name='delete-file'),
    
    path('api/knowledge-bases/<int:pk>/upload-files/', KnowledgeBaseViewSet.as_view({'post': 'upload_files'}), name='upload-files'),
    path('api/knowledge-bases/<int:pk>/delete-files/', KnowledgeBaseViewSet.as_view({'delete': 'delete_files'}), name='delete-files'),
    path('api/knowledge-bases/<int:pk>/upload-files/', KnowledgeBaseViewSet.as_view({'post': 'upload_file'}), name='upload-files'),
    
    path('api/knowledge-bases/<int:pk>/files/', KnowledgeBaseViewSet.as_view({'get': 'list_files'}), name='list-files'),  # 新增的路由

    # 加工资料
    path('api/knowledge-bases/<int:pk>/processing/upload-files/', ProcessingDataViewSet.as_view({'post': 'upload_files'}), name='upload-files'),
    path('api/knowledge-bases/<int:pk>/processing/files/', ProcessingDataViewSet.as_view({'get': 'list_files'}), name='list-files'),  # 新增的路由
    re_path(r'api/knowledge-bases/(?P<pk>\d+)/processing/download-file/(?P<file_id>[^/.]+)/', 
        ProcessingDataViewSet.as_view({'get': 'download_file'}), 
        name='download-file'),
    # path('api/knowledge-bases/<int:pk>/processing/download-file/', ProcessingDataViewSet.as_view({'get': 'download_file'}), name='download-file'),
   

    path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),  # Swagger UI 路由
    path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),  # ReDoc UI 路由
]
